<template>
  <div>
    Child1
    <p>
      <!-- dispatch是触发异步 -->
      <button @click="onMinus">异步减-2</button>&nbsp; &nbsp;
      <!-- commit是触发同步 -->
      <button @click="onAdd">同步+3</button>
    </p>
  </div>
</template>

<script>
import { mapMutations, mapActions } from 'vuex'
export default {
  methods: {
    /**
     * 参数1：模块的名字
     * 参数2：mutations的方法名
     */
    ...mapMutations('counter', ['add']),
    ...mapActions('counter', ['asyncMinus']),
    onMinus () {
      // this.$store.dispatch('counter/asyncMinus', 2)
      this.asyncMinus(2)
    },
    onAdd () {
      // this.$store.commit('counter/add', 3)
      this.add(3)
    }
  }
}
</script>
